/*****************************************************************************/
/*                                                                           */
/*    Domino Operation System Driver Module                                  */
/*                                                                           */
/*    Copyright (C) 2008 Laszlo Arvai                                        */
/*                                                                           */
/*    ------------------------------------------------------------------     */
/*    drvHighResTimer - High Resolution Timer Driver                         */
/*****************************************************************************/

///////////////////////////////////////////////////////////////////////////////
// Includes
#include <krnlHighResTimer.h>
#include <drvIOConfig.h>

///////////////////////////////////////////////////////////////////////////////
// Initialize high resolution timer
void drvInitHighResTimer(void)
{
	// high resolution timer uses core timer so
	// initialization must be done in drvSystemTimer.c
}	

///////////////////////////////////////////////////////////////////////////////
// Initialize high resolution timer
void krnlHighResDelay(unsigned int in_sleep_us)
{
 	unsigned int start_time = ReadCoreTimer();
	unsigned int diff_time;

  in_sleep_us *= sysCLOCK_FREQUENCY / 2 / 1000000;
	
	do
	{
		diff_time = ReadCoreTimer() - start_time;
	}	while( diff_time < in_sleep_us );
}

///////////////////////////////////////////////////////////////////////////////
// Read value of the high resolution timer (32bit)
dosDWord krnlGetHighResTimer(void)
{
	return ReadCoreTimer();
}
